<!-- TrainChangeStatusSetPracticeTime.html -->
<html class="base_gary_bg_color">
	<head>
		<meta charset="utf-8">
		<meta name="viewport" content="maximum-scale=1.0,minimum-scale=1.0,user-scalable=0,width=device-width,initial-scale=1.0"/>
		<meta name="format-detection" content="telephone=no, email=no, date=no, address=no">
		<title>批量更改学生实习状态提交页</title>
		<link rel="stylesheet" type="text/css" href="../../css/mui.min.css">
		<link rel="stylesheet" href="../../css/CFNetPP_Base.css">
		<link rel="stylesheet" href="../../css/weui.min.css">
		<link rel="stylesheet" href="../../css/base.css">
		<style type="text/css" media="screen">
			html {
				height: 100%;
				background: #f3f5f7;
			}
			body {
				height: 100%;
				background: #f3f5f7;
			}
			.weui_cells {
				margin-top: 0;
			}
			.changeStatus .practice_time_div {
				padding-bottom: 10px;
			}
			.base_grey {
				color: #333;
			}
			.changeStatus .mui-btn-warning {
				background: #ff9900;
				border-color: #ff9900
			}
		</style>
	</head>
	<body class="base_gary_bg_color changeStatus" >
		<div class="base_style_color " id='BarAppearance' style="height: 22px;width: 100%"></div>
		<div class="base_navigation_bar base_style_color base_navigation_item_bar">
			<a class="base_left_item" href="#" onclick="backClick()"> <img class="base_back_icon" src="../../image/icon_jiantou.png" alt=""> </a>
			<span>更改状态</span>
			<a class="base_right_item base_hide_item"> </a>
		</div>
		<div class="base_content_div" >
			<ul class="mui-table-view">
				<li class="mui-table-view-cell ">
					<p class="title" style="font-size: 14px; color: #666;">
						将已选择的<span id="person_num">0</span>人发送至：
					</p>
				</li>
				<li class="mui-table-view-cell">
					<a class="mui-navigate-right base_content_font" href="#" onclick="selectCompanyClick()"> <span class="base_grey left_text"> 企业名称 </span> <span id="company_name" class="base_grey right_text"> 请选择企业 </span> </a>
				</li>
				<li class="mui-table-view-cell">
					<a class="mui-navigate-right base_content_font" href="#" onclick="selectPostClick()"> <span class="base_grey left_text"> 岗位名称 </span> <span id="post_name" class="base_grey right_text"> 请选择岗位 </span> </a>
				</li>
				<li class="mui-table-view-cell">
					<a class="mui-navigate-right base_content_font" href="#" onclick="selectMasterClick()"> <span class="base_grey left_text"> 企业师傅 </span> <span id="master_name" class="base_grey right_text"> 请选择师傅 </span> </a>
				</li>
			</ul>
			<ul class="mui-table-view practice_time_div base_grey base_tag_font">
				<div style="padding-left: 15px;">
					<span class="base_grey base_content_font top_tag_text">实习时间：</span>
				</div>
				<div class="weui_cells">
					<div class="weui_cell base_grey base_tag_font">
						<div class="weui_cell_hd">
							<label for="" class="weui_label">开始</label>
						</div>
						<div class="weui_cell_bd weui_cell_primary">
							<input id="startdate" class="weui_input" type="date" value="">
						</div>
					</div>
					<div class="weui_cell base_grey base_tag_font">
						<div class="weui_cell_hd">
							<label for="" class="weui_label">结束</label>
						</div>
						<div class="weui_cell_bd weui_cell_primary">
							<input id="enddate" class="weui_input" type="date" value="">
						</div>
					</div>
				</div>
			</ul>
			<div class="bottom_btn_div">
				<button type="button" class="mui-btn mui-btn-warning mui-btn-block" onclick="submitclick()">
					提交
				</button>
			</div>
		</div>
	</body>
	<script type="text/javascript" src="../../script/api.js"></script>
	<script type="text/javascript" src="../../script/jquery.min.js"></script>
	<script type="text/javascript" src="../../script/MD5.js"></script>
	<script type="text/javascript" src="../../script/requestTool.js"></script>
	<script type="text/javascript">
		var companyid = '';
		var gwid = '';
		var masteruid = '';
		
		apiready = function() {
			SendBehaviorTrajectoriesNotifi1('0', '批量更改学生实习状态提交页', '114',api.pageParam.sourceurl, api.pageParam.sourcetitle, window.location.pathname,  document.title);
			setupNotifi();
			setupSelectNum();
		}
		function setupSelectNum() {
			var params = api.pageParam;
			var students = params.students;
			var num = students.length;
			$('#person_num').text(num);
		}

		function submitclick() {
//			SendBehaviorTrajectoriesNotifi1('1', '批量更改学生实习状态提交页', '114',api.pageParam.sourceurl, api.pageParam.sourcetitle, window.location.pathname,  document.title);
			if (companyid == '') {
				api.toast({
					msg : '请选择企业'
				});
				return;
			}
			if (gwid == '') {
				api.toast({
					msg : '请选择岗位'
				});
				return;
			}
			if (masteruid == '') {
				api.toast({
					msg : '请选择师傅'
				});
				return;
			}
			var startdateString = $('#startdate').val();
			if (startdateString == '') {
				api.toast({
					msg : '请选择实习开始时间'
				});
				return;
			}
			var enddateString = $('#enddate').val();
			if (enddateString == '') {
				api.toast({
					msg : '请选择实习结束时间'
				});
				return;
			}
			var startdate = timeStampWithString(startdateString);
			var enddate = timeStampWithString(enddateString);
			enddate += (24 * 60 * 60 - 1);
			//结束时间戳加上当天23小时59分59秒的时间
			if (enddate < startdate) {
				api.toast({
					msg : '实习结束时间不能早于开始时间,请重新选择!'
				});
				return;
			}
			var params = api.pageParam;
			api.showProgress({
				style : 'default',
				animationType : 'fade',
				title : '提交中...',
				text : '请稍候...',
				modal : false
			});
			var students = params.students;
			var studentsStr = students.join(',');
			var requestParam = {
				plan_id : params.planid,
				uid : $api.getStorage('cfnetppuid'),
				jid : $api.getStorage('cfnetppjid'),
				// classid : params.classid,
				students : studentsStr,
				companyid : companyid,
				gwid : gwid,
				sfid : masteruid,
				starttime : startdate,
				endtime : enddate
			};
			 var company_name=$('#company_name').html();//公司名
			 
			 var post_name=$('#post_name').html();//岗位名称
			 var master_name=$('#master_name').html();//师傅名称
			 var message="批量更改"+api.pageParam.selectedStuName+"等人的实习企业为"+company_name+";"+
				"实习岗位为"+post_name+";"+
				"实习导师为"+master_name+";"+
				"实习时间为"+startdateString+"至"+enddateString;
			
			cfnetppPOST(urlInternship, requestParam, false, function(data, status) {
				 requestParam["message"]=message;
				api.hideProgress();
				SendBusinessOperationsLogNotifi('更改学生实习状态提交页', '114', requestParam, requestParam, '', data, '更改学生实习状态提交接口', '114-01')
				if (status == 'success') {//网络请求成功
					if (data.status == '1') {//
						api.toast({
							msg : '提交成功！'
						});
						SendBehaviorTrajectoriesNotifi1('1', '批量更改学生实习状态提交页', '114',api.pageParam.sourceurl, api.pageParam.sourcetitle, window.location.pathname,  document.title);
						setTimeout(function() {
							api.closeToWin({
								name : 'TeachertInternshipIndex'
							});
						}, 1000);
					} else if (data.status == '2') {
						api.toast({
							msg : '所选时间与已分配的实习时间冲突!',
							duration : 5000,
							location : 'bottom'
						});
					} else if (data.status == '4') {
						api.toast({
							msg : '所选时间不在所选的实习计划期内!',
							duration : 5000,
							location : 'bottom'
						});
					} else if (data.status == '5') {
						api.toast({
							msg : '结束时间不能小于当前时间!',
							duration : 5000,
							location : 'bottom'
						});
					} else {
						api.toast({
							msg : '分配实习失败'
						});
					}
				} else {
					api.toast({
						msg : '网络异常请检查您的网络！'
					});
				}
			});
		}

		function selectCompanyClick() {
			api.openWin({useWKWebView:true,
				name : 'TrainSelectCompany',
				url : 'TrainSelectCompany.html'
			});
		}

		function selectPostClick() {
			if (companyid == '') {
				api.toast({
					msg : '请先选择企业'
				});
			} else {
				api.openWin({useWKWebView:true,
					name : 'TrainSelectPost',
					url : 'TrainSelectPost.html',
					pageParam : {
						cid : companyid
					}
				});
			}
		}

		function selectMasterClick() {
			if (companyid == '') {
				api.toast({
					msg : '请先选择企业'
				});
			} else {
				api.openWin({useWKWebView:true,
					name : 'TrainSelectMaster',
					url : 'TrainSelectMaster.html',
					pageParam : {
						cid : companyid
					}
				});
			}
		}

		function setupNotifi() {
			api.addEventListener({
				name : 'selectCompanyNotifi'
			}, function(ret, err) {
				companyid = ret.value.id;
				$('#company_name').text(ret.value.companyname);
			});
			api.addEventListener({
				name : 'selectPostNotifi'
			}, function(ret, err) {
				gwid = ret.value.id;
				$('#post_name').text(ret.value.postname);
			});
			api.addEventListener({
				name : 'selectMasterNotifi'
			}, function(ret, err) {
				masteruid = ret.value.masteruid;
				$('#master_name').text(ret.value.mastername);
			});
		}

		function backClick() {
			SendBehaviorTrajectoriesNotifi1('1', '更改学生实习状态提交页', '114',api.pageParam.sourceurl, api.pageParam.sourcetitle, window.location.pathname,  document.title);
			api.closeWin();
		}

		function timeStampWithString(timeString) {
			var tempStr = timeString.replace(/-/g, '/');
			var newTime = new Date(tempStr);
			return newTime.getTime() / 1000;
		}
	</script>
</html>